public class OppHistoryMap {
	
	// the idea was to use this in the membership status rollup trigger
	// not using for now since difficult to include in collections
	// may still do so later
	
	// TBD: rename this to remove all references to household, making this more general
	// new name: OppHistoryMap?
	
	// the id of the account, contact, or HH for which this is a history
	private id MasterId;
	
	public string ObjectType;
	
	private list<Opportunity> RelatedOpps = new list<Opportunity> ();

	// relatedCons only for HH	
	public list<Contact> RelatedCons = new list<Contact> ();
	
	// use these as generic ways to keep track of field values until ready to write to db
	public map<string,date> DateStats = new map<string,date> ();
	public map<string,string> TextStats = new map<string,string> ();
	
	
	//constructor 
	public OppHistoryMap (id argId) {
		MasterId = argId;
	}
	
	
	public void AddOpp (Opportunity newOpp ) {
		RelatedOpps.add (newOpp);	
	}
	
	
	public Opportunity GetLastOpp () {
		// return the last opp in the relatedOpps list, according to the order in which they were passed in
		
		integer nbrOpps = RelatedOpps.size();
		Opportunity lastOpp;
		
		if ( nbrOpps > 0 ) {
			lastOpp = RelatedOpps[nbrOpps - 1];	
		}
		
		return lastOpp;
	}


	public Opportunity GetFirstOpp () {
		// return the last opp in the relatedOpps list, according to the order in which they were passed in
		
		integer nbrOpps = RelatedOpps.size();
		Opportunity firstOpp;
		
		if ( nbrOpps > 0 ) {
			firstOpp = RelatedOpps[0];	
		}
		
		return firstOpp;
	}
	
	
	public double GetOppTotalAmt () {
	
		integer nbrOpps = RelatedOpps.size();
		double sumOpps = 0;

		if ( nbrOpps > 0 ) {
			for ( Opportunity thisOpp : RelatedOpps ) {
				double thisAmount = ( thisOpp.Amount == null ? 0 : thisOpp.Amount);
				sumOpps += thisAmount;
			}
		}		
		
		return sumOpps;

	}
	
	
	public double GetOppTotalForYear (integer targetYear) {
	
		double sumOpps = 0;
		
		for ( Opportunity thisOpp : RelatedOpps ) {
			date datCloseDate = thisOpp.CloseDate;
			integer thisYear = datCloseDate.year();
			if ( thisYear == targetYear ) {
				double thisAmount = ( thisOpp.Amount == null ? 0 : thisOpp.Amount);
				sumOpps += thisAmount;
			}
		}
		
		return sumOpps;
	}


}